﻿using UnityEngine;
using System.Collections;

namespace edit{
	public class Save : MonoBehaviour {
		bool savingLock = false;
		Main main;

		// Use this for initialization
		void Start () {
			main = Camera.main.transform.GetComponent<Main> ();
		}

		void OnMouseDown() {
			if (savingLock) {
				return;
			}
			savingLock = true;

			int[,] map = main.map;
			// 数组转字符串
			string str = "";
			//print (map.GetLength (0) + "x" + map.GetLength (1));
			for (int i = 0; i < map.GetLength(0); i++) {
				for (int j = 0; j < map.GetLength(1); j++) {
					str += map[i, j];
					if (j < map.GetLength(1) - 1) {
						str += ",";
					}
					if (j == map.GetLength(1) - 1) {
						str += ";";
					}
				}
			}
			//print (str);
			// 存储数据
			PlayerPrefs.SetString (Main.dataKey, str);
			Main.hasSaved = true;
			savingLock = false;
			// 弹出对话框，提示保存成功，点击任意位置退回index
			Block.hideCountLabel = true;
			GameObject dialog = GameObject.FindGameObjectWithTag("DIALOG_SAVE");
			dialog.transform.localScale = new Vector3 (1, 1, 1);
		}
		
		// Update is called once per frame
		void Update () {
		
		}
	}
}